Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: json HMR (fixes #9521) #9610

Merged
merged 2 commits into from
Aug 10, 2022
Merged

fix: json HMR (fixes #9521) #9610

merged 2 commits into from
Aug 10, 2022

Conversation

sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Aug 10, 2022

Description

This PR fixes #9521.

Additional context

Another way to solve this is to reorder this and move url = markExplicitImport(url) after moduleGraph.ensureEntryFromUrl instead of using removeImportQuery.

// mark non-js/css imports with `?import`
url = markExplicitImport(url)
// If the url isn't a request for a pre-bundled common chunk,
// for relative js/css imports, or self-module virtual imports
// (e.g. vue blocks), inherit importer's version query
// do not do this for unknown type imports, otherwise the appended
// query can break 3rd party plugin's extension checks.
if (
(isRelative || isSelfImport) &&
!/[\?&]import=?\b/.test(url) &&
!url.match(DEP_VERSION_RE)
) {
const versionMatch = importer.match(DEP_VERSION_RE)
if (versionMatch) {
url = injectQuery(url, versionMatch[1])
}
}
// check if the dep has been hmr updated. If yes, we need to attach
// its last updated timestamp to force the browser to fetch the most
// up-to-date version of this module.
try {
// delay setting `isSelfAccepting` until the file is actually used (#7870)
const depModule = await moduleGraph.ensureEntryFromUrl(
url,
ssr,
canSkipImportAnalysis(url)
)
if (depModule.lastHMRTimestamp > 0) {
url = injectQuery(url, `t=${depModule.lastHMRTimestamp}`)
}
} catch (e: any) {
// it's possible that the dep fails to resolve (non-existent import)
// attach location to the missing import
e.pos = pos
throw e
}


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@sapphi-red sapphi-red added feat: hmr p3-minor-bug An edge case that only affects very specific usage (priority) regression The issue only appears after a new release labels Aug 10, 2022
@patak-dev patak-dev merged commit e45d95f into vitejs:main Aug 10, 2022
@sapphi-red sapphi-red deleted the fix/json-hmr branch August 10, 2022 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: hmr p3-minor-bug An edge case that only affects very specific usage (priority) regression The issue only appears after a new release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

after vite3.0 not listening for changes to the JSON file
2 participants